home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_lib.arc / PCISRSTK.C < prev    next >
Text File  |  1990-08-09  |  2KB  |  67 lines

  1. /**
  2. *
  3. *  Name         pcisrstk -- Create the Interrupt Service Routine stack
  4. *
  5. *  Synopsis     ercode = pcisrstk(stksize);
  6. *               int  ercode       Error return code
  7. *               int  stksize      Desired stack size
  8. *
  9. *  Description  Interrupt service routines require their own stack.
  10. *               This function must be called before any ISR is set up
  11. *               so that stack space can be allocated.  The stksize,
  12. *               which must accommodate all ISRs, is allocated from
  13. *               the heap, and its segment and offset address are stored
  14. *               in the global variables, isrss and isrstk_base.  These
  15. *               values are passed to the ISR setup function, PCSETISR,
  16. *               and the ISR function dispatcher, INVISR.
  17. *
  18. *  Returns      If the requested size is not available, 1 is returned
  19. *               as an error value; otherwise 0 is returned.  The global
  20. *               variables isrss and isrstk_base are initialized.
  21. *
  22. *  Version      1.1  (C)Copyright Blaise Computing Inc.  1983, 1984
  23. *
  24. **/
  25. #include <compiler.h>
  26.  
  27. #if LDATA
  28. #define   NULL  0L
  29. #else
  30. #define   NULL  0
  31. #endif
  32.  
  33. unsigned isrss;                        /* ISR stack segment            */
  34. unsigned isrstk_base;                  /* Bottom of ISR stack          */
  35.  
  36. int pcisrstk(stksize)
  37. int stksize;
  38. {
  39.  
  40.     char     *pstk,*calloc();
  41.     unsigned cs,ss,ds,es;
  42. #if CI201A & LDATA
  43.     unsigned long ptrtoabs();
  44. #endif
  45.  
  46.     pstk = calloc(stksize,1);
  47.     if (pstk == NULL)
  48.         return(1);
  49.  
  50. #if LDATA
  51. #if CI201A
  52.     isrss       = (unsigned)((ptrtoabs(pstk) & 0xffff0L) >> 4L);
  53.     isrstk_base = (unsigned)(ptrtoabs(pstk) & 0xfL);
  54. #else
  55.     isrss       = (unsigned)(((long)(pstk) & 0xffff0L) >> 4L);
  56.     isrstk_base = (unsigned)((long)(pstk) & 0xfL);
  57. #endif
  58. #else
  59.     utsreg(&cs,&ss,&ds,&es);           /* Return segment reg values    */
  60.     isrss       = ds;
  61.     isrstk_base = (unsigned)pstk;
  62. #endif
  63.  
  64.     return(0);
  65.  
  66. }
  67.